package org.example.controller;

import org.example.bean.User;
import org.example.common.Result;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping("check")
    public Result checkUser(String username) {
//        int count = userService.checkUser(username);

        int count = 1;
        if (count > 0) {
            return Result.success();
        } else {
            return Result.fail();
        }
    }

    @ResponseBody
    @RequestMapping(path = "/login", method = RequestMethod.POST)
    public Result login(User user) {
        User result = userService.login(user);

        if (result != null) {
            return Result.success();
        } else {
            return Result.fail();
        }
    }

    @ResponseBody
    @RequestMapping(path = "/login2", method = RequestMethod.POST)
    public Result login2(@RequestBody User user) {
        User result = userService.login(user);

        if (result != null) {
            return Result.success();
        } else {
            return Result.fail();
        }
    }
}
